package com.zlzvip.android.app;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;

import com.pachong.android.baseuicomponent.activity.BaseActivity;
import com.zlzvip.android.R;
import com.zlzvip.android.common.web.CommonWebviewFragment;

import butterknife.Bind;

public class TopPicActivity extends BaseActivity {
    private CommonWebviewFragment mWebviewFragment;
    @Bind(R.id.wv_top)
    WebView mWvTop;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        hideToolbar();
        initToolbar();
        String mUrl = getIntent().getStringExtra("h5Link");
        mWebviewFragment = CommonWebviewFragment.newInstance(mUrl);
        getSupportFragmentManager().beginTransaction().add(R.id.wv_top, mWebviewFragment).commit();
    }

    private void initToolbar() {
        setTitle("");
        getCustomToolbar().addLeftImageButton(R.mipmap.back, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MainActivity.start(TopPicActivity.this);
                finish();
            }
        });
    }

    @Override
    public View createDataView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.activity_top_pic, null);
    }

    public static void start(Activity activity, String h5Link) {
        Intent intent = new Intent(activity, TopPicActivity.class);
        intent.putExtra("h5Link", h5Link);
        activity.startActivity(intent);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK)) {
            MainActivity.start(TopPicActivity.this);
            finish();
        }
        return false;
    }

}
